package yz.cp.back.common.service;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class AESService {
    private AES aes;
    @Value("${spring.aes.key:''}")
    private String aesKey;
    public String decode(String encodeStr){
        if(aes==null){
            aes = SecureUtil.aes(SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue(),aesKey.getBytes()).getEncoded());
        }
        return aes.decryptStrFromBase64(encodeStr);
    }
}
